export const binarySearch = (array: number[], num: number) => {
  let left = 0;
  let right = array.length - 1;

  while (left <= right) {
    let mid = Math.floor((left + right) / 2);
    let midNum = array[mid];
    if (midNum < num) {
      left = mid + 1;
    } else if (midNum > num) {
      right = mid - 1;
    } else {
      return mid;
    }
  }
};
